package com.kaiyidiannao.model.req.model;

import com.kaiyidiannao.data.DataCenter;
import com.kaiyidiannao.https.HttpUtils;
import com.kaiyidiannao.model.Result;
import com.kaiyidiannao.model.req.base.BaseCommand;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

/**
 *   购物车 （post） 异步请求 - 删除商品
 */
public class PostShoppingCarClear extends BaseCommand {

    private String TAG = "PostDayDayCouponShoppingCar";
    private String action = "clear";
    private String ajax = "1";
    private String key = null; //key缺省为空，表示清空购物车；key为“itemid-0-0-0”表示清空商品id为itemid的商品,如：1-0-0-0“
    private String userid;

    /**
     * 清空userid用户的购物车
     * @param userid
     */
    public PostShoppingCarClear(String userid) {
        this.userid = userid;
    }

    /**
     *
     * @param key 删除商品编号
     * @param userid 用户id
     */
    public PostShoppingCarClear(String key, String userid) {
        this.key = key;//-0-0-0
        this.userid = userid;
    }

    @Override
    public String getRequestUrl() {
        return DataCenter.POST_DAY_DAY_COUPON_CART;
    }

    @Override
    public HashMap<String, String> getRequestParamters() {
        HashMap<String, String> paramters = new HashMap<String, String>();
        paramters.put("action", action);
        paramters.put("ajax",ajax);
        paramters.put("userid", userid);
        if (null != key) {
            paramters.put("key", key);
        }
        return paramters;
    }

    @Override
    public Result go(String url, HashMap<String, String> paramters) { // 联网时后台执行
        // 根据请求参数返回请求数据
        return HttpUtils.postByHttpClient(url, paramters);
    }

    @Override
    public void yes(Result result) { //后台执行完毕后执行
        super.yes(result);
        DataCenter.getInstance().callBacks(DataCenter.flag.SHOPPING_CAR_DEL_SUCESS);
    }

    @Override
    public void no(Result result) {
        super.no(result);
        DataCenter.getInstance().callBacks(DataCenter.flag.SHOPPING_CAR_DEL_FAILED);
    }
}
